#ifndef CLCOMCOMMAND_H
#define CLCOMCOMMAND_H

#include <QtCore/qglobal.h>
#include <string>
#include <vector>
#include <QMap>
#include "CLComLibrarys_global.h"
//CLCOMLIBRARYS_EXPORT

using namespace std;
class CLCOMLIBRARYS_EXPORT CLComCommand
{
public:
    CLComCommand();
    ~CLComCommand();
public:
    void SetCommandKey(const char* commandkey);
    void SetCommandType(const char* commandkey);
    void SetParameteInt(const char* name, int nValue);
    void SetParameteBigInt(const char* name, qint64 llValue);
    void SetParameteDouble(const char*  name, double dValue);
    void SetParameteString(const char*  name, const char*  strValue);
    void SetOtherData(const char* name, void* pData, int nDatalen);

    const char* GetCommand();
    int GetCommandSize();

    int GetKVStrSize();
    bool GetKVStr(char* pOutStr, int nCapacityLen);

    void GetKeys(char* argKeys[], int &nCount);
    void ReleaseKeys(char* argKeys[], int nCount);
public:
    void Assignment(const char* commandstr);
    void AssignmentKV(const char* commandstr);
public:
    int GetCommandType();
    const char* GetCommandKey();
    int GetParameteInt(const char* name, int nDefaultValue);
    double GetParameteDouble(const char*  name, double dDefaultValue);
    const char* GetParameteString(const char*  name, const char*  strDefaultValue);
    const char* GetOtherData(const char*  name, int& nDataLen);

    bool HaveAttribute(const char* name);
public:
    void Data2File(FILE* pFile);
    void LoadFromFile(FILE* pFile, int nLen);

private:
    void* m_pData;
};

class CLCOMLIBRARYS_EXPORT CCommandFactory
{
public:
    static CLComCommand* Allocate();

    static void Giveback(CLComCommand* &pCMD);
};

class CLCOMLIBRARYS_EXPORT CStrCommandObserver
{
public:
    CStrCommandObserver();
    ~CStrCommandObserver();

protected:
    void RegisterOb(string keystr);
    void CancelOb(string keystr);

public:
    virtual void CommandArrival(CLComCommand* pcmd);
};

class CLCOMLIBRARYS_EXPORT IStrCommandCenter
{
public:
    static void Init();
    static void Release();

    static void Subscribe(
        string strcmd,
        CStrCommandObserver* pob);

    static void Cancel(
        string strcmd,
        CStrCommandObserver* pob);

    static void Cancel(
        CStrCommandObserver* pob);

public:
    static qint64 PostCommand(
        CLComCommand& command,
        bool bNeedResult);

    static bool GetCommandResult(qint64 id, CLComCommand& command);
};

#endif // CLCOMCOMMAND_H
